// JavaScript Document
//ext.js
//up toArray
//var efadfjeafdfeafedfa=
if(typeof TOOLS ==='undefined'){
    TOOLS=function(){}
}
;(function(){
	var Status=function(id,cssText){
	   if(typeof cssText === 'undefined'){ 
	       cssText = '' ;
	   }
	   this.loopfn;
	   this.draw
	   this.count=0;//计数函数运行多少次	
	   this.oldcount=0;
	   this.cdiff=0;
	   this.freq=1000;
	   this.idfps=id;//显示帧率的层的id
	   this.stop=false;
	   var oDiv=document.createElement('div');
	   var body=document.getElementsByTagName('body')[0];
	   oDiv.id=id;
	   oDiv.style.cssText=cssText;
	   body.insertBefore(oDiv,body.childNodes[0])
	}	
	Status.prototype.setLoop=function(fn){
	   this.loopfn=fn;    	
	}
	Status.prototype.setdraw=function(fn){
	   this.draw=fn;    	
	}
	Status.prototype.runLoop=function(){
		console.log('Status.prototype.runLoop start')
		console.log(this.loopfn)
	    console.log('Status.prototype.runLoop end')
	   this.loopfn()		
	}
	Status.prototype.refreshFps=function(){
		
		window.setInterval(function(){

	   var timeDifference=(this.count-this.oldcount)*(1000/this.freq)
	   timeDifference = parseInt(timeDifference*100)/100
	   this.cdiff=	timeDifference;
            if(this.count>99999){
                this.count  = 0;
            }
	  try{
	  document.getElementById(this.idfps).innerHTML=this.cdiff//+'/'+this.count+'|'+this.stop+
	  }catch(e){console.error(e)}
	 // console.log('Status.prototype.refreshFps ->window.setInterval')
	 // console.log(this)
		
	   this.oldcount = this.count }.__$bind$__(this)  ,this.freq)
	}
	
	Status.prototype.run=function(){
		var that =this;
		this.setLoop( function(){
            that.count++;

	        try{that.draw()}catch(e){  	  }	 
	
	        if(!that.stop){
	        window.requestAnimationFrame(that.loopfn);  
	        }
        })
      
	    this.runLoop();
        this.refreshFps()	
	}
	Status.prototype.stopToggle=function(){
	    if(this.stop){
			this.stop=false;
			this.runLoop();
		}else{
			this.stop=true;	
		}
	}
	window.Statuss=window.Status=Status;
	if(typeof window.TOOLS==='function' || typeof window.TOOLS==='object'){
	    window.TOOLS.Status=Status;
	}
	
})()


TOOLS.mkDiv=function(id,cssText,innerHTML){
    var innerHTML =innerHTML || "";
    var body=document.getElementsByTagName('body')[0];
    var div = document.createElement("div");
    div.id=id;
    div.innerHTML=innerHTML;
    div.style.cssText=cssText;
    try{body.insertBefore(div,body.childNodes[0]);	}catch(e){ }
}


TOOLS.getLocalTime=function (timestamp,chinese){
    if (!timestamp){
        var date=new Date()
		var ms =date.getMilliseconds();
        datetime = date.toLocaleString()+":"+(  ms<10 ? ('00'+ms) :    ms<100? ('0'+ms):ms   );
    }else{
        datetime = new Date(parseInt(timestamp)*1000).toLocaleString();
    }
    if (!chinese){
        return datetime.replace(/年|月/g, '-').replace(/日/g, '');
    }
    return datetime;
}




//end